package com.beiben.quality.controller;

import java.util.List;

import com.beiben.trialproduce.samplecar.domain.SampleCar;
import com.beiben.work.process.domain.FileProcessUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.beiben.quality.domain.QaQualityInfo;
import com.beiben.quality.service.IQaQualityInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 质量信息Controller
 * 
 * @author gx
 * @date 2021-03-08
 */
@RestController
@RequestMapping("/quality/quality")
public class QaQualityInfoController extends BaseController
{
    @Autowired
    private IQaQualityInfoService qaQualityInfoService;

    /**
     * 查询质量信息列表
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:list')")
    @GetMapping("/list")
    public TableDataInfo list(QaQualityInfo qaQualityInfo)
    {
        startPage();
        List<QaQualityInfo> list = qaQualityInfoService.selectQaQualityInfoList(qaQualityInfo);
        return getDataTable(list);
    }

    /**
     * 导出质量信息列表
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:export')")
    @Log(title = "质量信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QaQualityInfo qaQualityInfo)
    {
        List<QaQualityInfo> list = qaQualityInfoService.selectQaQualityInfoList(qaQualityInfo);
        ExcelUtil<QaQualityInfo> util = new ExcelUtil<QaQualityInfo>(QaQualityInfo.class);
        return util.exportExcel(list, "quality");
    }

    /**
     * 获取质量信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:query')")
    @GetMapping(value = "/{qualityId}")
    public AjaxResult getInfo(@PathVariable("qualityId") Long qualityId)
    {
        AjaxResult ajax = AjaxResult.success();
        if(null!=qualityId){
            ajax.put("qaQualityInfo", qaQualityInfoService.selectQaQualityInfoById(qualityId));
            ajax.put("groupLists", qaQualityInfoService.selectQaQualityInfoByQualityId(qualityId));
        }
        return ajax;
    }

    /**
     * 新增质量信息
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:add')")
    @Log(title = "质量信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QaQualityInfo qaQualityInfo)
    {
        return toAjax(qaQualityInfoService.insertQaQualityInfo(qaQualityInfo));
    }



    /**
     * 修改质量信息
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:edit')")
    @Log(title = "质量信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QaQualityInfo qaQualityInfo)
    {
        return toAjax(qaQualityInfoService.updateQaQualityInfo(qaQualityInfo));
    }

    /**
     * 删除质量信息
     */
    @PreAuthorize("@ss.hasPermi('quality:quality:remove')")
    @Log(title = "质量信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{qualityIds}")
    public AjaxResult remove(@PathVariable Long[] qualityIds)
    {
        return toAjax(qaQualityInfoService.deleteQaQualityInfoByIds(qualityIds));
    }

    /**
     * 导入质量信息数据
     */
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<QaQualityInfo> util = new ExcelUtil<QaQualityInfo>(QaQualityInfo.class);
        return util.importTemplateExcel("质量信息数据");
    }

    @Log(title = "质量信息导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('quality:quality:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<QaQualityInfo> util = new ExcelUtil<QaQualityInfo>(QaQualityInfo.class);
        List<QaQualityInfo> qaQualityInfoList = util.importExcel(file.getInputStream());
        String message = qaQualityInfoService.importSampleQuality(qaQualityInfoList,updateSupport);
        return AjaxResult.success(message);
    }
}
